Server_Detected = call compile preprocessFile "scripts\common.sqf";

private ["_veh", "_vehName", "_vehType", "_markerPos", "_markerObj", "_degrees", "_cDir", "_sDir", "_newPosX", "_newPosY" ,"_newPosZ", "_iUpdate"];

If (typename(_this) == "ARRAY") then {
	_veh = _this select 0;
} else {
	_veh = _this;
};
If (isnil("_veh")) exitwith {};

_vehName = vehicleVarName _veh;
_vehType = typeof _veh;

diag_log Format["Initializing vehicle %1 (%2) as MHQ", _vehType, _vehName];

_markerPos = getMarkerPos X_MHQ_Marker;
If (((_markerPos select 0) == 0) && ((_markerPos select 1) == 0) && ((_markerPos select 2) == 0)) then {
	_markerObj = createMarker [X_MHQ_Marker, getPos _veh];
	X_MHQ_Marker setMarkerShape "ICON";
	X_MHQ_Marker setMarkerType "b_inf";
	X_MHQ_Marker setMarkerColor "ColorBlue";
	X_MHQ_Marker setMarkerText "MHQ";
	
	diag_log Format["Marker MHQ_Mobile_Respawn is created"];
};

_iUpdate = 0;
while { (alive _veh) } do {
		X_MHQ_Marker setMarkerPos getpos _veh;
		If ((speed _veh) <= 0.2) then {
			Sleep 10;
		} else {
			Sleep 1;
		};
		_iUpdate = _iUpdate + 1;
		If (_iUpdate > 59) then {
			_iUpdate = 0;
			diag_log Format["New MHQ Marker Position: %1", getMarkerPos X_MHQ_Marker];
		};
};